package cn.edu.scau.cmi.zhuangjunsheng.Client;



import java.util.Set;


import cn.edu.scau.cmi.zhuangjunsheng.singleton.Marshal;
import javafx.application.Application;
import javafx.geometry.Insets;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;

public class multitonClient extends Application{

	private TextField nameField = new TextField();
	private Button build = new Button("添加");
	private Label label = new Label();
	BorderPane Pane = new BorderPane();
	VBox vBox = new VBox(10);
	private String string = "";
	
	public static void main(String[] args) {
		launch(args);
	}
	
	public void start(Stage primaryStage) {
		// TODO Auto-generated method stub
		vBox.setPadding(new Insets(50,100,100,100));
		vBox.getChildren().add(new Label("请输入要添加的元帅名字:"));
		vBox.getChildren().add(nameField);
		vBox.getChildren().add(build);
		vBox.getChildren().add(label);
		//gridPane.add(build, 2, 2);
		build.setOnAction(e -> setName());
		
		Pane.setTop(vBox);
		Scene scene = new Scene(Pane,600,500);
		primaryStage.setTitle("多例模式");
		primaryStage.setScene(scene);
		primaryStage.show();
	}
	private void setName() {
		//Set<Marshal> marshalSet = Marshal.addInstance(nameField.getText());
		if(Marshal.isFull) {
			label = new Label("对不起，已经有十个元帅了，"+nameField.getText()+"不能再是元帅！");
			vBox.getChildren().add(label);
		}
		else {
			//Iterator<Marshal> marshalIterator = marshalSet.iterator();
			string = "";
			/*
			for(Marshal marshal : marshalSet) {
				string  = string + marshal.getName() + marshal.toString() + "\n";
			}
			*/
			label.setText(string);
		}
		//System.out.println(chairman);
		
		//vBox.getChildren().add(label);
	}
}	


